package group2.beans;

import group2.core.database.DatabaseUtil;
import group2.core.entities.Comment;
import group2.core.entities.Post;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 * Used for populating the rightmost div with the latest comments and posts.
 * 
 * @author cnilsson
 */
@ManagedBean
@ViewScoped
public class ViewLatestActivitiesBean implements Serializable{
    
    private final static int MAX_COMMENTS = 5;
    private final static int MAX_POSTS = 5;
 
    private List<Comment> latestComments;
    private List<Post> latestPosts;

    public List<Comment> getLatestComments() {
        return latestComments;
    }

    public List<Post> getLatestPost() {
        return latestPosts;
    }

    private void populateComments() {
        //Returns the MAX_COMMENTS first elements 
        this.latestComments = DatabaseUtil.getInstance().getLatestComments(MAX_COMMENTS);
    }

    private void populatePosts() {
        //Returns the MAX_POSTS first elements 
        this.latestPosts = DatabaseUtil.getInstance().getLatestPosts(MAX_POSTS);

    }

    /** Creates a new instance of ViewLatestCommentsBean */
    public ViewLatestActivitiesBean() {
        populatePosts();
        populateComments();
    }
}
